﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using System.Web.Security;
using System.Threading;

namespace HK2009.Common
{
    /// <summary>
   /// </summary>
    public class StringUtil
    {
        private static string passWord;	//Encryption string of character 

        /// <summary>
        /// The judgment inputs whether digit 
        /// </summary>
        /// <param name="num">Must judge string of character </param>
        /// <returns></returns>
        static public bool VldInt(string num)
        {
            #region
            try
            {
                Convert.ToInt32(num);
                return true;
            }
            catch { return false; }
            #endregion
        }

        /// <summary>
        /// string transfers the money demonstration 
        /// </summary>
        /// <param name="strValue">Must transform the string of character </param>
        /// <returns>After transformation string type result </returns>
        public static string StrToMoney(string strValue)
        {
            try
            {
                strValue = "$" + String.Format("{0:N2}", Convert.ToDouble(strValue));
            }
            catch
            {
                strValue = "";
            }
            return strValue;
        }
        /// <summary>
        /// Revises the special character 
        /// </summary>
        /// <param name="str">Must replace string of character </param>
        /// <returns></returns>
        static public string CheckStr(string str)
        {
            #region
            return str.Replace("<br />\r\n", "\r\n").Replace("&", "&amp;").Replace("'", "&apos;").Replace(@"""", "&quot;").Replace(" ", "&nbsp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(" ", "&nbsp;").Replace(" where ", " wh&#101;re ").
                Replace(" select ", " sel&#101;ct ").Replace(" insert ", " ins&#101;rt ").Replace(" create ", " cr&#101;ate ").Replace(" drop ", " dro&#112 ").
                Replace(" alter ", " alt&#101;r ").Replace(" delete ", " del&#101;te ").Replace(" update ", " up&#100;ate ").Replace(" or ", " o&#114; ").Replace("\"", @"&#34;").
                Replace("\r\n", "<br />\r\n");
            #endregion
        }
        /// <summary>
        /// Whether the  picture  exist 
        /// </summary>
        /// <param name="jpgPath"></param>
        /// <returns></returns>
        public static string imageExist(string jpgPath, string Size)
        {
            if (jpgPath == "")
            {
                jpgPath = "/Images/no.jpg";
            }
            if (!System.IO.File.Exists(GetMapPath(jpgPath)))
            {
                if (Size == "big")
                {
                    jpgPath = "/Images/nophoto_big.jpg";
                }
                else if (Size == "mid")
                {
                    jpgPath = "/Images/nophoto_mid.jpg";
                }
                else
                {
                    jpgPath = "/Images/nophoto_small.jpg";
                }
            }
            return jpgPath;
        }
        /// <summary>
        /// Restores the special character 
        /// </summary>
        /// <param name="str">Must replace string of character </param>
        /// <returns></returns>
        static public string UnCheckStr(string str)
        {
            #region
            return str.Replace("&amp;", "&").Replace("&apos;", "'").Replace("&quot;", @"""").Replace("&nbsp;", " ").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&nbsp;", " ").Replace(" wh&#101;re ", " where ").
                Replace(" sel&#101;ct ", " select ").Replace(" ins&#101;rt ", " insert ").Replace(" cr&#101;ate ", " create ").Replace(" dro&#112 ", " drop ").
                Replace(" alt&#101;r ", " alter ").Replace(" del&#101;te ", " delete ").Replace(" up&#100;ate ", " update ").Replace(" o&#114; ", " or ").Replace(@"&#34;", "\"");
            #endregion
        }
        /// <summary>
        /// Obtains the current absolute way 
        /// </summary>
        /// <param name="strPath">Assigns way </param>
        /// <returns>Absolute way </returns>
        public static string GetMapPath(string strPath)
        {
            if (HttpContext.Current != null)
            {
                return HttpContext.Current.Server.MapPath("~/").ToString() + strPath.Substring(1, strPath.Length - 1);
            }
            else //Non-web program reference 
            {
                return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
            }
        }

        /// <summary>
        /// Whether the judgment picture does exist 
        /// </summary>
        /// <param name="jpgPath"></param>
        /// <returns></returns>
        public static string imageExist(string jpgPath)
        {

            if (!System.IO.File.Exists(GetMapPath(jpgPath)))
            {
                jpgPath = "/Images/nophoto.gif";
            }
            return jpgPath;
        }
       
        /// <summary>
        /// Interception character string function 
        /// </summary>
        /// <param name="str">Must intercept string of character </param>
        /// <param name="num">Interception string of character length </param>
        /// <param name="ReplacStr">Uses in string of character which replaces </param>
        /// <returns></returns>
        static public string GetSubString(string str, int num,string ReplacStr)
        {
            #region
            
            int allnum = 0;
            int i, j;

            for (i = 0; i < str.Length; i++)
            {
                if (str[i] >= ' ' && str[i] <= '~') allnum++;
                else allnum += 2;
            }

            if (allnum <= num) return str;

            for (i = 0, j = 0; i < num; j++)
            {
                if (str[j] >= ' ' && str[j] <= '~') i++;
                else i += 2;
            }

            if (i - num > 0) j--;

            return str.Substring(0, j) + ReplacStr;
            #endregion
        }

        /// <summary>
        /// Filtration infed information 
        /// </summary>
        /// <param name="text">Content </param>
        /// <returns></returns>
        public static string InputText(string text)
        {
            #region
            text = Regex.Replace(text, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); //删除脚本
            text = Regex.Replace(text, "[\\s]{2,}", " ");	//two or more spaces
            text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n");	//<br>
            text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " ");	//&nbsp;
            text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty);	//any other tags
            text = text.Replace("'", "''");
            text = HttpContext.Current.Server.HtmlEncode(text).Trim(); 
            return text;
            #endregion
        }
        /// <summary>
        /// Judgment by specific character or in string of character separation string of character, whether to contain another string of character 
        /// </summary>
        /// <param name="str">Is judged the string of character </param>
        /// <param name="stringarray">Possibly contains is judged the string of character the string of character </param>
        /// <param name="strsplit">Separation character or string of character </param>
        /// <returns>true: Contains, false: Does not contain </returns>
        public static bool IsCompriseStr(string str, string stringarray, string strsplit)
        {
            if (stringarray == "" || stringarray == null)
                return false;
            str = str.ToLower();
            string[] stringArray = SplitString(stringarray.ToLower(), strsplit);
           
            for (int i = 0; i < stringArray.Length; i++)
            {
                if (str.IndexOf(stringArray[i]) > -1)
                {
                    return true;
                }
            }
            return false;
        }
       
         /// <summary>
        /// The division string of character, the preservation is an array 
         /// </summary>
        /// <param name="strContent">String of character </param>
        /// <param name="strSplit">Separation character or string of character </param>
        /// <returns>Finally array </returns>
         public static string[] SplitString(string strContent, string strSplit)
         {
             if (strContent.IndexOf(strSplit) < 0)
             {
                 string[] tmp = { strContent };
                 return tmp;
             }
             return Regex.Split(strContent, @strSplit.Replace(".", @"\."), RegexOptions.IgnoreCase);
         }

        /// <summary>
         /// Production random number 
        /// </summary>
        /// <returns></returns>
        static public string GenerateCheckCode()
        {
            #region
            int number;
            char code;
            string checkCode = String.Empty;

            System.Random random = new Random();

            for (int i = 0; i < 5; i++)
            {
                number = random.Next();

                if (number % 2 == 0)
                    code = (char)('0' + (char)(number % 10));
                else
                    code = (char)('A' + (char)(number % 26));

                checkCode += code.ToString();
            }

            return checkCode;
            #endregion
        }

        /// <summary>
        /// Production random number 
        /// </summary>
        /// <returns></returns>
        static public string GenerateCheckCode(int Length)
        {
            #region
            int number;
            char code;
            string checkCode = String.Empty;

            System.Random random = new Random();

            for (int i = 0; i < Length; i++)
            {
                number = random.Next();

                if (number % 2 == 0)
                    code = (char)('0' + (char)(number % 10));
                else
                    code = (char)('A' + (char)(number % 26));

                checkCode += code.ToString();
            }

            return checkCode;
            #endregion
        }

        /// <summary>
        /// The Chinese character code transforms, solves IE address fence Chinese 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        static public string Strencode(string input)
        {
            #region
            return System.Web.HttpUtility.UrlEncode(InputText(input));
            #endregion
        }

     
        /// <summary>
        /// String of character encryption 
        /// </summary>
        /// <param name="PasswordString">Must encrypt string of character </param>
        /// <param name="PasswordFormat">Must encrypt category </param>
        /// <returns></returns>
        static public string EncryptPassword(string PasswordString, string PasswordFormat)
        {
            #region
            switch (PasswordFormat)
            {
                case "SHA1":
                    {
                        passWord = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "SHA1");
                        break;
                    }
                case "MD5":
                    {
                        passWord = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "MD5");
                        
                        break;
                    }
                default:
                    {
                        passWord = string.Empty;
                        break;
                    }
            }
            return passWord;
            #endregion
        }

        public static bool IsEmailAddress(string email)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
        }

        /// <summary>
        /// Obtains the browser edition 
        /// </summary>
        /// <param name="strPara"></param>
        /// <returns></returns>
        public static string Browser(string strPara)
        {
            string strResult = null;
            strResult = strPara.Replace("MSIE", "Internet Explorer");
            return strResult;
        }
        /// <summary>
        /// Obtains the operating system edition 
        /// </summary>
        /// <param name="strPara"></param>
        /// <returns></returns>
        public static string Windows(string strPara)
        {
            string strResult = null;
            switch (strPara)
            {
                case "Windows NT 5.0":
                    strResult = "Windows 2000";
                    break;
                case "Windows NT 5.1":
                    strResult = "Windows XP";
                    break;
                case "Windows NT 5.2":
                    strResult = "Windows Server 2003";
                    break;
            }
            return strResult;
        }
        /// <summary>
        /// Obtains the browser and the operating system edition 
        /// </summary>
        /// <param name="intNum">1 expresses the browser, 2 expression operating system </param>
        /// <returns></returns>
        public static string Agent(int intNum)
        {
            string strResult = null;
            strResult = HttpContext.Current.Request.UserAgent.Split(';')[intNum].Trim().Replace("(", "").Replace(")", "");
            switch (intNum)
            {
                case 1:
                    strResult = Browser(strResult);//Obtains the browser edition 
                    break;
                case 2:
                    strResult = Windows(strResult);//Obtains the operating system edition 
                    break;
            }
            return strResult;
        }
       
        /// <summary>
        /// Record diary to the log.txt document in 
        /// </summary>
        /// <param name="str">Diary content </param>
        public static void log(string str)
        {
            //if (Config.debugValue)
            //{
                string filename = System.Web.HttpContext.Current.Request.MapPath("~/upload/") + "log.txt";
                System.IO.StreamWriter w = System.IO.File.AppendText(filename);
                w.WriteLine("\r\nStart:" + str + " (" + DateTime.Now + ")");
                w.Flush();
                w.Close();
            //}
        }

        #region Cut string and out of the string for ...
        /// <summary>
        /// Cut string 
        /// </summary>
        /// <param name="strValue">input string </param>
        /// <param name="strNum">string length</param>
        /// <returns></returns>
        public static string CutString(string strValue, int strNum)
        {
            string strNew = string.Empty;
            if (strValue.Length > strNum)
            {
                strNew = strValue.Substring(0, strNum);
                strNew = strNew + "...";
            }
            else
            {
                strNew = strValue;
            }
            return strNew;
        }
        #endregion

      
        public static string GetStatus(object status)
        {
            string name=string.Empty;

            if (status.ToString() == "0")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Invalid";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "無效";
                }
                else
                {
                    name = "无效";
                }
            }
            else
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Valid";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "有效";
                }
                else
                {
                    name = "有效";
                }
            }
            return name;
        }


        public static string GetTruckStatus(object status)
        {
            string name = string.Empty;

            string s = status.ToString();
            if (s == "0")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Invalid";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "無效";
                }
                else
                {
                    name = "无效";
                }
            }
            else if (s == "1")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Valid";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "有效";
                }
                else
                {
                    name = "有效";
                }
            }
            else
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Fault";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "報障";
                }
                else
                {
                    name = "报障";
                }
            }

            return name;
        }


        public static string GetSexName(object sex)
        {
            string name = string.Empty;
            string s = sex.ToString();
            if (s == "0")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Female";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "女";
                }
                else
                {
                    name = "女";
                }
            }
            else
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Male";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "男";
                }
                else
                {
                    name = "男";
                }
            }

            return name;
        }


        public static string GetYesNo(object yn)
        {
            string name = string.Empty;
            string s = yn.ToString();
            if (s == "0")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "No";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "否";
                }
                else
                {
                    name = "否";
                }
            }
            else
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Yes";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "是";
                }
                else
                {
                    name = "是";
                }
            }

            return name;
        }

        /// <summary>
        /// 获取托运单主表状态
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        public static string GetBnStatus(object status)
        {
            string name = string.Empty;
            if (status.ToString() == Enums.BookingNoteStatus.NEW.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "New";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "新增";
                }
                else
                {
                    name = "新增";
                }
            }
            else if (status.ToString() == Enums.BookingNoteStatus.CHECK.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Check";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "審核";
                }
                else
                {
                    name = "审核";
                }
            }
            else
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消";
                }
                else
                {
                    name = "取消";
                }
            }
            return name;
        }
        public static string GetBNDStatus(object status)
        {
            string name = string.Empty;
            if (status.ToString() == Enums.BookingNoteDtlStatus.NEW.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "New";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "新增";
                }
                else
                {
                    name = "新增";
                }
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.BOOKING.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Booking";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已Booking";
                }
                else
                {
                    name = "已Booking";
                }
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.ARRANGED.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Arranged";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已分配";
                }
                else
                {
                    name = "已分配";
                }
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.CCONFIRM.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Contractor Confirm Job";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "運輸隊確認Job";
                }
                else
                {
                    name = "运输队确认Job";
                }              
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.CONFIRMBOOKING.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Company Confirm Job";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "公司確認Job";
                }
                else
                {
                    name = "公司确认Job";
                }    
               
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.PRINTTEMP.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Print";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "打印暫收證明";
                }
                else
                {
                    name = "打印暂收证明";
                }                   
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.MATECONFIRM.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "MateReceipt";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "尾紙確認";
                }
                else
                {
                    name = "尾纸确认";
                }                 
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.CANCELBOOKING.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel Booking";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消Booking";
                }
                else
                {
                    name = "取消Booking";
                }      
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.CANCELARRANGE.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel Arranged";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消分配";
                }
                else
                {
                    name = "取消分配";
                }                      
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.COCANCEL.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Company Cancel Confirm Job";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "公司取消確認Job";
                }
                else
                {
                    name = "公司取消确认Job";
                }      
               
            }
            else if (status.ToString() == Enums.BookingNoteDtlStatus.CCANCEL.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Contractor Cancel Job";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "運輸隊取消Job";
                }
                else
                {
                    name = "运输队取消Job";
                }     
               
            }
            else if (status.ToString() == Enums.ShippingOrderStatus.CEXPEDITEDTRUCK.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "CexpeditedTruck";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消派車";
                }
                else
                {
                    name = "取消派车";
                }     
            }
            else
            {
                name = "";
            }

            return name;
        }

        public static string GetShipperOrderStatus(object status)
        {
            string name = string.Empty;
            if (status.ToString() == Enums.ShippingOrderStatus.NEW.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "New";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "新增";
                }
                else
                {
                    name = "新增";
                }
            }
            else if (status.ToString() == Enums.ShippingOrderStatus.CHECK.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Check";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已審核";
                }
                else
                {
                    name = "已审核";
                }

            }
            else if (status.ToString() == Enums.ShippingOrderStatus.CONFIM.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Company Confirm";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "公司已確認";
                }
                else
                {
                    name = "公司已确认";
                }

            }
            else if (status.ToString() == Enums.ShippingOrderStatus.PRINT.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Print";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "打印暫收證明";
                }
                else
                {
                    name = "打印暂收证明";
                }     

            }
            else if (status.ToString() == Enums.ShippingOrderStatus.CANCEL.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已取消";
                }
                else
                {
                    name = "已取消";
                }    

            }
            else if (status.ToString() == Enums.ShippingOrderStatus.CANCELCONFIM.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Company Cancel Confirm";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "公司已取消確認";
                }
                else
                {
                    name = "公司已取消确认";
                }
            }
            else if (status.ToString() == Enums.ShippingOrderStatus.CANCELARRANGE.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel Arranged";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消分配";
                }
                else
                {
                    name = "取消分配";
                }
            }
            else if (status.ToString() == Enums.ShippingOrderStatus.MATECONFIRM.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "MateReceipt";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "尾紙確認";
                }
                else
                {
                    name = "尾纸确认";
                }     
            }
            else if(status.ToString() ==Enums.ShippingOrderStatus.CEXPEDITEDTRUCK.ToString("d"))
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "CexpeditedTruck";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消派車";
                }
                else
                {
                    name = "取消派车";
                }     
            }
            else
            {
                name = "";
            }
            return name;
        }

        public static string GetBookingStatusName(object o)
        {
            string name = string.Empty;

            string s = o.ToString();
            if (s == "0")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Booking";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "落單";
                }
                else
                {
                    name = "落单";
                }   
           
            }
            else if (s == "1")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Arranged";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已分配";
                }
                else
                {
                    name = "已分配";
                }                  
            }
            else if (s == "2")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel Arranged";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已取消分配";
                }
                else
                {
                    name = "已取消分配";
                } 
            } 
            else if (s == "3")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已取消";
                }
                else
                {
                    name = "已取消";
                } 
            }
            else
            {
                name = "";
            }

            return name;
        }

        public static string GetBookingNoteDtlStatusName(object o)
        {
            string name = string.Empty;

            string s = o.ToString();
            if (s == "0")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "New";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "新增";
                }
                else
                {
                    name = "新增";
                }

            }
            else if (s == "1")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Booked";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已Booking";
                }
                else
                {
                    name = "已Booking";
                }
            }
            else if (s == "2")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Arranged";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已分配";
                }
                else
                {
                    name = "已分配";
                }
            }
            else if (s == "3")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Confirm Job";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "運輸隊確認Job";
                }
                else
                {
                    name = "运输队确认Job";
                }
            }
            else if (s == "4")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Company Confirm Job";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "公司確認Job";
                }
                else
                {
                    name = "公司确认Job";
                }
            }
            else if (s == "5")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Printed";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "已打印暫收證明";
                }
                else
                {
                    name = "已打印暂收证明";
                }
            }
            else if (s == "6")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Mate Received";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "尾紙確認";
                }
                else
                {
                    name = "尾纸确认";
                }
            }
            else if (s == "7")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel booking";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消Booking";
                }
                else
                {
                    name = "取消Booking";
                }
            }
            else if (s == "8")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel Arrange";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消分配";
                }
                else
                {
                    name = "取消分配";
                }
            }
            else if (s == "9")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel Confirm Job";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "公司取消確認Job";
                }
                else
                {
                    name = "公司取消确认Job";
                }
            }
            else if (s == "10")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel Job";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消Job";
                }
                else
                {
                    name = "取消Job";
                }
            }
            else if (s == "11")
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("en"))
                {
                    name = "Cancel Send Truck";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString().ToLower().Equals("zh-hk"))
                {
                    name = "取消派車";
                }
                else
                {
                    name = "取消派车";
                }
            }
            else
            {
                name = "";
            }

            return name;
        }

        public static string GetTime(string str)
        {
            if (str != string.Empty)
            {
                Regex reg = new Regex("(([0][0-9])|([1][0-9])|([2][0-3]))([0-5][0-9])");
                if (reg.IsMatch(str))
                {
                    return " " + str.Substring(0, 2) + ":" + str.Substring(2, 2);
                }
                else
                {
                    return " 00:00";
                }
            }
            else
            {
                return " 00:00";
            }
        }
    }
}
